//
//  KDTabBarController.m
//  警用舆情平台
//
//  Created by 魏强 on 15/5/12.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "KDInspectController.h"
#import "KDNavigationController.h"
#import "KDAutoMonitorController.h"
#import "KDWorkingReportController.h"
#import "GBReportViewController.h"
#import "KDAccount.h"
#import "KDAccountTool.h"
#import "KDReginDataTool.h"
#import "KDMonitorController.h"
//#import "KDLiaisonProfessionController.h"
#import "GBShortMessageViewController.h"
#import "KDGetVpnServiceTool.h"
#import "KDSearchHomeController.h"
#import "KDOverwideNavigationController.h"
#import "KDRole.h"
#import "LXActionSheet.h"
#import "ELCImagePickerHeader.h"
#import <MobileCoreServices/UTCoreTypes.h>
#import "KDInspectSecondController.h"
#import "KDsubscribController.h"
#import "WQSearchController.h"
#import "KDCollectController.h"
#import "KDReportCenterController.h"
#import "ZZPhotoKit.h"
#import "KDReportController.h"
#import "KDMessagePushController.h"
#import "KDHomeViewController.h"
//#import "ZZPhotoKit.h"
CGFloat const underView_height = 130;
@interface KDInspectController ()<LXActionSheetDelegate,ELCImagePickerControllerDelegate, UIImagePickerControllerDelegate,UINavigationControllerDelegate, WQSearchControllerDelegate, UISearchBarDelegate>{
    UIBarButtonItem *rightPhotoBtn; //右上角照片button，从照片库或摄像头上传照片或视频
    UIButton *addPhotoBtn; //增加照片的按钮
    LXActionSheet *actionSheet; //点击右上角照片按钮，出现的选择菜单
    float PhotoWidth; //每张照片的宽度；
    int photoCount; //用于保存照片的个数
    int photoColumn; //当每一行的照片满了，下一回照片个数清零
    UIButton *cancleBtn; //取消选择照片按钮
    UIButton *sendBtn; //发送消息按钮；
    
    UITextView *GBtextView; //用户输入文字的textview,放在photoview上；
    UILabel *GBLable; //textview默认的内容放在photoview上；
    
    LXActionSheet *actionSheetVideo; //点击选择是否写入照片库 0-写入 1-取消
    UIButton *cameraBtn; //右上角的上报按钮，既相机样式的按钮
    
    UIImagePickerController *ipc; //显示照片的界面
    NSMutableArray *imgListP; //用于盛放用户选择的照片
    NSMutableArray *imgCopy; //用于盛放新照片的数组
    UILongPressGestureRecognizer *longPress; // 长按手势
}
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *firstView_Constraint_W;
/** *  监测系统板块 */
@property (weak, nonatomic) IBOutlet UIView *firstView;
@property (weak, nonatomic) IBOutlet UIButton *keywordBtn;
@property (weak, nonatomic) IBOutlet UILabel *keywordLabel;
@property (weak, nonatomic) IBOutlet UIButton *webBtn;
@property (weak, nonatomic) IBOutlet UILabel *webLb;

@property (weak, nonatomic) IBOutlet UIButton *authorBtn;
@property (weak, nonatomic) IBOutlet UILabel *authorLb;
@property (weak, nonatomic) IBOutlet UIButton *AppBtn;
@property (weak, nonatomic) IBOutlet UILabel *AppLb;

/** *  作者监测和网站监测之间的水平距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *authorBtn_to_webBtn_W;
/** *  关键词监测和网站监测之间的水平距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *webBtn_to_keywordBtn_w;
/** *  作者监测和APP监测之间的水平距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *AppBtn_to_authorBtn_w;


@property (nonatomic, weak) UIScrollView *scrollView;
/** *  预警上报板块 */
@property (weak, nonatomic) IBOutlet UIView *secondView;
@property (weak, nonatomic) IBOutlet UIButton *warmingBtn;
@property (weak, nonatomic) IBOutlet UILabel *warmingLabel;
@property (weak, nonatomic) IBOutlet UIButton *reportBtn;
@property (weak, nonatomic) IBOutlet UILabel *reportLabel;
/** *  舆情预警和上报中心之间的水平距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *reportBtn_to_warmingBtn_w;
/** *  搜索导航板块 */
@property (weak, nonatomic) IBOutlet UIView *thirdView;
@property (weak, nonatomic) IBOutlet UIButton *webSearchBtn;
@property (weak, nonatomic) IBOutlet UILabel *webSearchLb;
@property (weak, nonatomic) IBOutlet UIButton *weiboSearchBtn;
@property (weak, nonatomic) IBOutlet UILabel *weiboSearchLb;
@property (weak, nonatomic) IBOutlet UIButton *outsideSearchBtn;
@property (weak, nonatomic) IBOutlet UILabel *outsideSearchLb;
@property(weak,nonatomic)IBOutlet UIButton * messagePushBtn;
/** *  全网搜索和微博搜索之间的水平距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *weiboSearchBtn_to_webSearchBtn_w;
/** *  境外导航和微博搜索之间的水平距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *outsideSearchBtn_weiboSearchBtn_w;

/** *  个人中心板块 */
@property (weak, nonatomic) IBOutlet UIView *fourthView;
@property (weak, nonatomic) IBOutlet UIButton *inspectBtn;
@property (weak, nonatomic) IBOutlet UILabel *inspectLb;
@property (weak, nonatomic) IBOutlet UIButton *collectBtn;
@property (weak, nonatomic) IBOutlet UILabel *collectLb;
/** *  我的收藏和个人设置之间的水平距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *settingBtn_to_collectBtn_w;
/** *  监测系统板块和预警上报板块之间的垂直距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondView_to_firstView_H;
/** *  搜索导航板块和监测系统板块之间的垂直距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *thirdView_to_secondView_H;
/** *  个人中心板块和搜索导航板块之间的垂直距离 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *fourthView_to_firstView_H;

/**  <#Description#> */
@property (nonatomic, strong) KDNavigationController *searchController;

@end

@implementation KDInspectController

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    self.firstView_Constraint_W.constant = self.view.width;
    if(IS_PAD){
        
        // 高度约束添加到firstView身上(主要是改fourthView里的顶部图片，由于控件事依赖firstView，所以要改firstView)
        NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.fourthView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:170];
        [self.view addConstraint:heightConstraint];
        
    }
    
    KDRole *role = [KDAccountTool role];
    self.role = role;
    [self.view layoutIfNeeded];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSearchBar];
//    [self getVpnModel];
    [self createPhotoButton];
}

- (void)setRole:(KDRole *)role{
    _role = role;
    [self setUpRole];
}
/**
 *  用于设置哪些板块要隐藏
 */
- (void)setUpRole{
    if (self.role) {
        if (self.role.inspect) {
            self.fourthView.hidden = YES;
            self.fourthView_to_firstView_H.constant =- underView_height;
        }else{
            self.fourthView.hidden = NO;
            self.fourthView_to_firstView_H.constant = 0;
        }
        if (!self.role.keyword && !self.role.weisite && !self.role.author && !self.role.app) {//如果四个都没有的话，那么久把整个监测系统板块隐藏
            self.firstView.hidden = YES;
            self.secondView_to_firstView_H.constant = - underView_height;
        }else{//四个里面至少存在一个
            self.firstView.hidden = NO;
            self.secondView_to_firstView_H.constant = 0;
            if (self.role.keyword) {//关键词判断
                self.keywordBtn.hidden = NO;
                self.keywordLabel.hidden = NO;
                self.webBtn_to_keywordBtn_w.constant = 0;
            }else{
                self.keywordBtn.hidden = YES;
                self.keywordLabel.hidden = YES;
                self.webBtn_to_keywordBtn_w.constant = -screenW *0.25;
            }
            if (self.role.weisite) {//网站监测判断
                self.webBtn.hidden = NO;
                self.webLb.hidden = NO;
                self.authorBtn_to_webBtn_W.constant = 0;
            }else{
                self.webBtn.hidden = YES;
                self.webLb.hidden = YES;
                self.authorBtn_to_webBtn_W.constant = -screenW *0.25;
            }
            if (self.role.author) {//作者监测判断
                self.authorBtn.hidden = NO;
                self.authorLb.hidden = NO;
                self.AppBtn_to_authorBtn_w.constant = 0;
            }else{
                self.authorBtn.hidden = YES;
                self.authorLb.hidden = YES;
                self.AppBtn_to_authorBtn_w.constant = -screenW *0.25;
            }
            if (self.role.app) {//app监测判断
                self.AppBtn.hidden = NO;
                self.AppLb.hidden = NO;
            }else{
                self.AppBtn.hidden = YES;
                self.AppLb.hidden = YES;
            }
            
        }
        if (!self.role.yuJing && !self.role.report) {//判断舆情预警板块是不是需要隐藏
            self.secondView.hidden = YES;
            self.thirdView_to_secondView_H.constant = - underView_height;
        }else{
            self.secondView.hidden = NO;
            self.thirdView_to_secondView_H.constant = 0;
            if (!self.role.yuJing) {
                self.warmingBtn.hidden = YES;
                self.warmingLabel.hidden = YES;
                self.reportBtn_to_warmingBtn_w.constant = -screenW *0.25;
            }else{
                self.warmingBtn.hidden = NO;
                self.warmingLabel.hidden = NO;
                self.reportBtn_to_warmingBtn_w.constant = 0;
            }
            if (!self.role.report) {//上报中心判断
                self.AppBtn.hidden = YES;
                self.AppLb.hidden = YES;
            }else{
                self.AppBtn.hidden = NO;
                self.AppLb.hidden = NO;
            }
        }
        if (!self.role.search &&!self.role.weiboSearch && !self.role.proxy) {//如果整个搜索板块都没有的话，就隐藏
            self.thirdView.hidden = YES;
//            self.fourthView_to_thirdView_H.constant = - underView_height;
        }else{
            if (!self.role.search) {
                self.webSearchBtn.hidden = YES;
                self.webSearchLb.hidden = YES;
                self.weiboSearchBtn_to_webSearchBtn_w.constant = -screenW *0.25;
            }
            if (!self.role.weiboSearch) {
                self.weiboSearchLb.hidden = YES;
                self.weiboSearchBtn.hidden = YES;
                self.outsideSearchBtn_weiboSearchBtn_w.constant =-screenW *0.25;
            }
            if (!self.role.proxy) {
                self.outsideSearchLb.hidden = YES;
                self.outsideSearchBtn.hidden = YES;
            }
        }
    }
}

#pragma mark - 版面设计
- (void)setupSearchBar{
    UISearchBar *searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, screenW - 200, 30)];
    searchbar.delegate = self;
    
    self.navigationItem.titleView = searchbar;
    
}
- (void)setUpScrollView{
    //加一个挡板
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = [UIColor clearColor];
    [self.view addSubview:view];
    //初始化underScrollView
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    self.scrollView = scrollView;
    scrollView.frame = CGRectMake(0, 0, screenW, screenH);
    
    //    underScrollView.contentSize = CGSizeMake(BTN_WIDTH * PAGE_NUMBER, HEADSCROLLH);
    scrollView.backgroundColor = BackGroundColor;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.scrollView];
    [self setUpUnderView];
}
- (void)setUpUnderView{
//    for (int i = 0; i < 4; i++) {
//        UIView *underView = [UIView alloc]initWithFrame:<#(CGRect)#>
//    }
}

#pragma mark - 初始化右上角照片btn
-(void)createPhotoButton
{
    imgListP = [NSMutableArray array];
    imgCopy = [NSMutableArray array];
    PhotoWidth = (self.view.frame.size.width - 50) / 4.0;
    photoCount = 0;
    photoColumn = 0;
    
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    rightView.backgroundColor = KDColor;
    
    cameraBtn = [UIButton buttonWithType:0];
    cameraBtn.frame = CGRectMake(0, 0, 40, 40);
    [cameraBtn addTarget:self action:@selector(PickThePhoto) forControlEvents:UIControlEventTouchUpInside];
    [cameraBtn setImage:[UIImage imageNamed:@"拍照上报"] forState:UIControlStateNormal];
    
    longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
    longPress.minimumPressDuration = 1.0;
    [cameraBtn addGestureRecognizer:longPress];
    
    //  [rightView addSubview:shortmessageBtn];
    [rightView addSubview:cameraBtn];
    UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:rightView];
    self.navigationItem.rightBarButtonItem = menuButton2;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - 监测按钮被点击了
- (IBAction)monitorBtnClick:(UIButton *)sender {
        KDMonitorController *monitor = [[KDMonitorController alloc] init];
    NSString *title;
    switch (sender.tag) {
        case 1:
            title = @"关键词监测";
            break;
        case 2:
            title = @"网站监测";
            break;
        case 3:
            title = @"作者监测";
            break;
        case 4:
            title = @"APP监测";
            break;
        default:
            break;
    }
    monitor.mainType = sender.tag -1;
    [self presentToController:monitor title:title];
}
/**
 *  预警上报板块的按钮被点击了
 */
- (IBAction)secondViewBtnClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:{//自主监测按钮被点击了
            KDAutoMonitorController *homeCtrl = [[KDAutoMonitorController alloc]init];
            [self presentToController:homeCtrl title:@"自主监测"];
            break;
        }
        case 2:{//预警推送按钮被点击了
            KDsubscribController *messageCenter = [[KDsubscribController alloc] init];
            [self presentToController:messageCenter title:@"预警推送"];
            break;
        }
        case 3:{//境外按钮被点击了
            KDOverwideNavigationController *messageCenter = [[KDOverwideNavigationController alloc] init];
            [self presentToController:messageCenter title:@"境外导航"];
            break;
        }
        case 4:{//消息推送按钮被点击了
            KDMessagePushController *messageCenter = [[KDMessagePushController alloc] init];
            [self presentToController:messageCenter title:@"消息推送"];
            break;
        }
        default:
            break;
    }
}
/**
 *  搜索导航板块的按钮被点击了
 */
- (IBAction)thirdViewBtnClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:{//舆情报告按钮被点击了
            KDWorkingReportController *homeCtrl = [[KDWorkingReportController alloc]init];
//            homeCtrl.type = sender.tag -1;
            [self presentToController:homeCtrl title:@"舆情报告"];
            break;
        }
        case 2:{//我的收藏按钮被点击了
            KDCollectController *homeCtrl = [[KDCollectController alloc]init];
            [self presentToController:homeCtrl title:@"我的收藏"];
            break;
        }
        case 3:{//上报中心按钮被点击了
            KDReportCenterController *messageCenter = [[KDReportCenterController alloc] init];
            [self presentToController:messageCenter title:@"上报中心"];
            break;
        }
        default:
            break;
    }
}

- (IBAction)fourthViewBtnClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:{//责任巡查按钮被点击了
            KDInspectSecondController *homeCtrl = [[KDInspectSecondController alloc]init];
            [self presentToController:homeCtrl title:@"责任巡查"];
            break;
        }
        case 2:{//上报中心按钮被点击了
//            KDSettingViewController *messageCenter = [[KDSettingViewController alloc] init];
//            [self presentToController:messageCenter title:@"设置"];
            break;
        }
        default:
            break;
    }
}


#pragma mark - 点击右上角按钮的操作
-(void)PickThePhoto
{
    photoCount = 0;
    photoColumn = 0;
    [imgCopy removeAllObjects];
    [imgListP removeAllObjects];
    
    if (cameraBtn.isEnabled)
    {
        actionSheet = [[LXActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@[@"拍照",@"从手机相册选择"]];
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [actionSheet showInView:window];
        
//        cameraBtn.enabled = !cameraBtn.enabled;
    }
}

- (void)searchBarClick{
    WQSearchController *ctr = [[WQSearchController alloc]initWithNibName:@"WQSearchController" bundle:nil];
    ctr.delegate = self;
    ctr.kSearchHistory = NSStringFromClass([self class]);
    self.searchController = [[KDNavigationController alloc]initWithRootViewController:ctr];
    
    [ctr showInViewController:self];
}
#pragma mark - 响应长按手势的代码
-(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
{
    if(gesture.state == UIGestureRecognizerStateBegan)
    {
        //选择图片成功后跳转界面
        GBReportViewController *collect = [[GBReportViewController alloc] init];
        collect.longPress = 2;
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationItem setBackBarButtonItem:backItem];
        [self.navigationController pushViewController:collect animated:YES];
    }
}
- (void)presentToController:(UIViewController *)ctrl title:(NSString *)title{
    KDNavigationController *nav = [[KDNavigationController alloc] initWithRootViewController:ctrl];
    nav.navigationBar.topItem.title= title;
    // 推送到该控制器
    [self presentViewController:nav animated:YES completion:nil];
}
#pragma mark - LXActionSheetDelegate代理
- (void)didClickOnButtonIndex:(NSInteger *)buttonIndex
{
    WS(ws);
    //KDLog(@"%d",(int)buttonIndex);
    int btnIndex = (int)buttonIndex;
    if (!btnIndex) {
        
        ZZCameraController *cameraController = [[ZZCameraController alloc]init];
        cameraController.takePhotoOfMax = 1;
        
        cameraController.isSaveLocal = NO;
        [cameraController showIn:self result:^(id responseObject){
            KDReportController *report = [[KDReportController alloc]init];
            KDReportParam *param  = [[KDReportParam alloc]init];
            report.param = param;
            NSMutableArray *arr = [NSMutableArray arrayWithArray:report.picArray];
            NSArray *photos = (NSArray *)responseObject;
            [arr insertObjects:photos atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, photos.count)]];
            
            report.picArray = arr;
            [ws.navigationController pushViewController:report animated:YES];

            
//            [_collectionView reloadData];
        }];
    }else if (btnIndex == 1){
        //点中了倒数第一个，就让他去相册找
        
        ZZPhotoController *photoController = [[ZZPhotoController alloc]init];
        photoController.selectPhotoOfMax = 1;
        //设置相册中完成按钮旁边小圆点颜色。
        //        photoController.roundColor = [UIColor greenColor];
        
        [photoController showIn:self result:^(id responseObject){
            KDReportController *report = [[KDReportController alloc]init];
            KDReportParam *param  = [[KDReportParam alloc]init];
            report.param = param;

            NSMutableArray *arr = [NSMutableArray arrayWithArray:report.picArray];
            NSArray *photos = (NSArray *)responseObject;
            [arr insertObjects:photos atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, photos.count)]];
            report.picArray = arr;
            //                        KDLog(@"重载");
            [ws.navigationController pushViewController:report animated:YES];

        }];
    }
}

#pragma mark - UIImagePickerControllerDelegate 在选择完图片后调用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //销毁控制器
    [picker dismissViewControllerAnimated:YES completion:nil];
    //photoview出现
    //隐藏navigationbar
    self.navigationController.navigationBar.hidden = NO;
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    //获得图片
    UIImage *image = info[UIImagePickerControllerEditedImage];
    if(image == nil)
    {
        image = info[UIImagePickerControllerOriginalImage];
    }
    //保存图片
    [imgListP addObject:image];
    [imgCopy addObject:image];
    
    //选择图片成功后跳转界面
    GBReportViewController *collect = [[GBReportViewController alloc] init];
    
    for(int i = 0; i < imgListP.count; i++)
    {
        [collect.photoArrayS addObject:imgListP[i]];
    }
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationItem setBackBarButtonItem:backItem];
    [self.navigationController pushViewController:collect animated:YES];
    //KDLog(@"%lu",(unsigned long)imgCopy.count);
    //[photosCollectionView reloadData];
}

#pragma mark - imagePicker拍照取消操作
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    photoCount = 0;
    photoColumn = 0;
    [imgCopy removeAllObjects];
    [imgListP removeAllObjects];
    // 销毁控制器
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)displayPickerForGroup:(ALAssetsGroup *)group
{
    ELCAssetTablePicker *tablePicker = [[ELCAssetTablePicker alloc] initWithStyle:UITableViewStylePlain];
    tablePicker.singleSelection = YES;
    tablePicker.immediateReturn = YES;
    
    ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:tablePicker];
    elcPicker.maximumImagesCount = 1;
    elcPicker.imagePickerDelegate = self;
    elcPicker.returnsOriginalImage = YES; //Only return the fullScreenImage, not the fullResolutionImage
    elcPicker.returnsImage = YES; //Return UIimage if YES. If NO, only return asset location information
    elcPicker.onOrder = NO; //For single image selection, do not display and return order of selected images
    tablePicker.parent = elcPicker;
    // Move me
    tablePicker.assetGroup = group;
    [tablePicker.assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];
    [self presentViewController:elcPicker animated:YES completion:nil];
}

#pragma mark ELCImagePickerControllerDelegate Methods
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];
    
    //隐藏navigationbar
    self.navigationController.navigationBar.hidden = YES;
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:[info count]];
    for (NSDictionary *dict in info)
    {
        if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypePhoto)
        {
            if ([dict objectForKey:UIImagePickerControllerOriginalImage])
            {
                UIImage* image=[dict objectForKey:UIImagePickerControllerOriginalImage];
                [images addObject:image];
                [imgListP addObject:image];
                [imgCopy addObject:image];
                //KDLog(@"代理imgcopy = %@",imgCopy);
                //[photosCollectionView reloadData];
            }
            else
            {
                KDLog(@"UIImagePickerControllerReferenceURL = %@", dict);
            }
        }
        else if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypeVideo)
        {
            if ([dict objectForKey:UIImagePickerControllerOriginalImage])
            {
                UIImage* image=[dict objectForKey:UIImagePickerControllerOriginalImage];
                [images addObject:image];
                [imgListP addObject:image];
                [imgCopy addObject:image];
                //[photosCollectionView reloadData];
            }
            else
            {
                KDLog(@"UIImagePickerControllerReferenceURL = %@", dict);
            }
        }
        else
        {
            KDLog(@"Uknown asset type");
        }
    }
    
    //选择图片成功后跳转界面
    GBReportViewController *collect = [[GBReportViewController alloc] init];
    
    for(int i = 0; i < imgListP.count; i++)
    {
        [collect.photoArrayS addObject:imgListP[i]];
    }
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationItem setBackBarButtonItem:backItem];
    [self.navigationController pushViewController:collect animated:YES];
}
#pragma mark - 从照片库选择图片的取消操作
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
    [imgCopy removeAllObjects];
    [imgListP removeAllObjects];
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - searchBarDelegate
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    [self searchBarClick];
}
#pragma mark - WQSearchControllerDelegate
- (void)questionSearchCancelButtonClicked:(WQSearchController *)controller{
    
    [controller hide:^{
        KDLog(@"questionSearchCancelButtonClicked");
    }];
}
@end
